package servlet;

import impl.SaveFileJava;
import thread.ComRunThread;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "JavaThreadServlet")
public class JavaThreadServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String sourceName = request.getParameter("sourceName");
        String sourceText = request.getParameter("sourceText");
        String inputText = request.getParameter("inputText");
        long time = System.currentTimeMillis();
        SaveFileJava saveFileJava = new SaveFileJava(sourceName + time, sourceText, inputText);

        ComRunThread cr = new ComRunThread("java", sourceName + time);
        String result = cr.StartUp();
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println(result);
        response.getWriter().close();
    }
}
